package com.example.myapplication.found;


import android.text.TextUtils;

import com.example.myapplication.found.bean.JijinBean;
import com.example.myapplication.found.bean.StockBean;
import com.example.myapplication.found.bean.StockBean2;
import com.example.myapplication.found.bean.StockKlineBean;
import com.example.myapplication.shortvideo.utils.GsonUtil;
import com.example.myapplication.util.TimeUtil;
import com.google.gson.reflect.TypeToken;

import org.jetbrains.annotations.NotNull;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;

/**
 * @author: rongfeng
 * @date: 2021/12/20
 * @description
 */
public class Deal {

    int loop = 7;
    float midelK = 3500;
    float lastDealK = 3500;
    public double jiJin = 10000;
    public double zhaiQuan = 10000;
    float rate = 0.5f;
    int steap = 140;
    float rateSteap = 0.05f;
    double maxMoney, minMoney = 20000, maxRate, minRate = 0.5;
    double chaMoney;
    int dealBy, dealSeal;
    StockKlineBean stockKlineBean;
    float downK = 1000000f;

    double jiJin2 = 10000;
    double zhaiQuan2 = 10000;

    public double jiJin3 = 100;
    public double zhaiQuan3 = 100;

    static String code = "163402";

    //    050002 沪深300

    int dealCount;

    static boolean isLog = true;
    JijinBean jijinBean1;
    static int loopIndex = 0;

    static List<String> currentFound;

    public static void main(String[] args) throws Exception {
//        getStock();
//        loop();
        Deal deal = new Deal();
        deal.start();
    }

    private static void loop() {
        if (loopIndex < mList.size()) {
            currentFound = mList.get(loopIndex);
            code = currentFound.get(0);
            loopIndex++;
            Deal deal = new Deal();
            deal.start();
        } else {
            double avg = 0;
            for (double item : lianhua) {
                avg += item;
            }

            double shouyiavg = 0;
            for (double item : shouyilu) {
                shouyiavg += item;
            }

            double avgShouyi = 0;
            int count = 0;
            for (List<String> item : mList) {
                if (item.get(3) != null && !item.get(3).equals("")) {
                    count++;
                    double shouyi = Double.parseDouble(item.get(3));
                    avgShouyi += shouyi;
                }

            }

            System.out.println("平均收益率1 " +  (avgShouyi/count));

            System.out.println("平均收益率2 " + (shouyiavg / shouyilu.size()));
            System.out.println("平均年化2 " + (avg / lianhua.size()));
        }
    }

    static double APY(double shouyi, int year)// 计算年利率
    {
        int n;
        double q, F, P;
//        System.out.printf("复利终值:");
        F = shouyi;
//        System.out.printf("存入本金:");
        P = 20000;
//        System.out.printf("存入年限:");
//        System.out.printf("年复利次数:");
        n = 1;
        q = n * (Math.pow(F / P, 1.0 / (year * n)) - 1);

        return q;
//        System.out.println("从" + P + "到" + F + "需要" + q);
    }

    static volatile List<List<String>> mList = new ArrayList<>();

    public static void getStock() {
        File file = new File("D:\\Android\\AndroidStudioProjects\\MyApplication\\app\\src\\main\\assets\\text\\found.txt");
        try {
            if (file.exists()) {
                String str;
                FileInputStream fileInputStream = new FileInputStream(file);
                InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

                StringBuffer sb = new StringBuffer();
                String text = null;
                while ((text = bufferedReader.readLine()) != null) {
                    sb.append(text);
                }
                str = sb.toString();

                fileInputStream.close();
                inputStreamReader.close();
                bufferedReader.close();

                List<String> list = GsonUtil.parse(str, new TypeToken<List<String>>() {
                }.getType());

                for (String bean : list) {

                    String[] item = bean.split(",");
                    List<String> ints = Arrays.asList(item);

                    mList.add(ints);
                }

//                System.out.println(mList);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    StringBuilder stringBuilder = new StringBuilder();


    public float zhangdie;


    public void rate() {
        downK = 100000;

        if (zhangdie != 0) {
            lastStockKlineBean.chg = zhangdie;
        }
        jiJin3 = jiJin3 + jiJin3 * (lastStockKlineBean.chg / 100);

        //买入
        float shouPan = lastStockKlineBean.shouPan;
        float currentsTeap = (Math.abs(midelK - shouPan) / steap);
        rate = 0.5f;
        boolean isDeal = true;
        if (currentsTeap == 0) {
            rate = 0.5f;
        } else {
            if (shouPan > midelK) {
//                        rate -= currentsTeap * ((currentsTeap) * 0.005f);
                rate -= currentsTeap * rateSteap;
            } else if (shouPan < downK) {
                downK = shouPan;
//                        rate += currentsTeap * (currentsTeap * 0.005f);
                rate += currentsTeap * rateSteap;
            } else {
                isDeal = false;
            }
        }
        double mairu = 0;
        if (isDeal) {
            if (rate > 1) {
                rate = 1;
                mairu = zhaiQuan3;
            } else {
                if (rate < 0) {
                    rate = 0;
                }
                mairu = (zhaiQuan3 + jiJin3) * rate - jiJin3;
                if (mairu > zhaiQuan3) {
                    mairu = zhaiQuan3;
                }
            }

            zhaiQuan3 = zhaiQuan3 - mairu;
            jiJin3 = jiJin3 + mairu;
            dealBy += 1;

            if (isLog) {
                stringBuilder.append("更新时间" + TimeUtil.getImageTakenTime(System.currentTimeMillis())).append("\n");
                stringBuilder.append(lastStockKlineBean.date).append("\n");
                stringBuilder.append("收盘 ").append(lastStockKlineBean.shouPan).append("\n");
                stringBuilder.append("midelK ").append(midelK).append("\n");
                stringBuilder.append("当前比例 ").append(rate).append("\n");

                if (mairu > 0) {
                    stringBuilder.append("买入 ").append(mairu).append("\n");
                } else {
                    stringBuilder.append("卖出 ").append(mairu).append("\n");
                }


                stringBuilder.append("基金 ").append((rate * 100) + "% " + jiJin3).append("\n");
                stringBuilder.append("债券 ").append((1 - rate) * 100 + "% " + zhaiQuan3).append("\n");
                stringBuilder.append("余额 ").append((jiJin3 + zhaiQuan3)).append("\n");

                System.out.println(stringBuilder.toString());
            }
            if (simpleCallback != null) {
                simpleCallback.callback(stringBuilder);
            }

            loop();
        }

    }


    interface Callback {
        void callback(StringBuilder stringBuilder);
    }

    public static Callback simpleCallback;

    public void start() {
        String url = "https://push2his.eastmoney.com/api/qt/stock/kline/get?secid=1.000011&klt=101&fqt=1&lmt=10000&end=20500000&iscca=1&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6%2Cf7%2Cf8&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61%2Cf62%2Cf63%2Cf64&ut=f057cbcbce2a86e2866ab8877db1d059&forcect=1";
        getKlines(url);
        getKlines2("http://api.fund.eastmoney.com/f10/lsjz?callback=jQuery18303632289946266538_1654519967808&fundCode=" + code + "&pageIndex=1&pageSize=3000&startDate=&endDate=&_=1654520586102");
    }

    public void testFound(StockKlineBean stockKlineBean, JijinBean jijinBean1) {

        dealCount++;
        this.stockKlineBean = stockKlineBean;
        this.jijinBean1 = jijinBean1;
        float shouPan = stockKlineBean.shouPan;
        float k = shouPan - lastDealK;

        double yuE = jiJin + jiJin * (stockKlineBean.chg / 100);
        jiJin = yuE;
        zhaiQuan = zhaiQuan + zhaiQuan * 0.00016f;


        double yuE2 = jiJin2 + jiJin2 * (jijinBean1.getJZZZLInt() / 100);
        jiJin2 = yuE2;
        zhaiQuan2 = zhaiQuan2 + zhaiQuan2 * 0.00016f;


        if (Math.abs(k) > steap) {
            if (k > 0) {
                if (shouPan > midelK) {

                    //卖出
                    float currentsTeap = (Math.abs(shouPan - midelK) / steap);
                    rate = 0.5f;


                    rate -= currentsTeap * rateSteap;

                    double maichu = 0;
                    double maichu2 = 0;
                    if (rate < 0) {
                        rate = 0;
                        maichu = jiJin;

                        maichu2 = jiJin2;
                    } else {
                        maichu = Math.abs(yuE - (zhaiQuan + yuE) * rate);
                        if (maichu > yuE) {
                            maichu = yuE;
                        }

                        maichu2 = Math.abs(yuE2 - (zhaiQuan2 + yuE2) * rate);
                        if (maichu2 > yuE2) {
                            maichu2 = yuE2;
                        }
                    }

                    zhaiQuan += maichu;
                    jiJin = yuE - maichu;

                    zhaiQuan2 += maichu2;
                    jiJin2 = yuE2 - maichu2;


                    dealSeal += 1;
                    if (isLog) {
                        System.out.println(stockKlineBean.date);
                        if (downK != 100000) {
                            System.out.println("重置");
                        }
                        System.out.println("收盘 " + stockKlineBean.shouPan + " midelK " + midelK);
                        System.out.println("rate " + rate);
                        System.out.println("卖出 " + maichu);
                        System.out.println("基金 " + (rate * 100) + "% " + jiJin);
                        System.out.println("债券 " + (1 - rate) * 100 + "% " + zhaiQuan);
                        System.out.println("余额 " + (jiJin + zhaiQuan));

                        System.out.println();
                        System.out.println("卖出2 " + maichu2);
                        System.out.println("基金2 " + (rate * 100) + "% " + jiJin2);
                        System.out.println("债券2 " + (1 - rate) * 100 + "% " + zhaiQuan2);
                        System.out.println("余额2 " + (jiJin2 + zhaiQuan2));
                        System.out.println();

                    }
                    downK = 100000;
                }
            } else {
                //买入
                if (stockKlineBean.date.equals("2016-12-28")) {
                    System.out.println();
                }
                float currentsTeap = (Math.abs(midelK - shouPan) / steap);
                rate = 0.5f;
                boolean isDeal = true;
                if (currentsTeap == 0) {
                    rate = 0.5f;
                } else {
                    if (shouPan > midelK) {
//                        rate -= currentsTeap * ((currentsTeap) * 0.005f);
                        rate -= currentsTeap * rateSteap;
                    } else if (shouPan < downK) {
                        downK = shouPan;
//                        rate += currentsTeap * (currentsTeap * 0.005f);
                        rate += currentsTeap * rateSteap;
                    } else {
                        isDeal = false;
                    }
                }
                if (isDeal) {
                    double mairu = 0;
                    double mairu2 = 0;
                    if (rate > 1) {
                        rate = 1;
                        mairu = zhaiQuan;
                        mairu2 = zhaiQuan2;
                    } else {
                        if (rate < 0) {
                            rate = 0;
                        }
                        mairu = Math.abs((zhaiQuan + yuE) * rate - yuE);
                        if (mairu > zhaiQuan) {
                            mairu = zhaiQuan;
                        }

                        mairu2 = Math.abs((zhaiQuan2 + yuE2) * rate - yuE2);
                        if (mairu2 > zhaiQuan2) {
                            mairu2 = zhaiQuan2;
                        }
                    }

                    zhaiQuan = zhaiQuan - mairu;
                    jiJin = yuE + mairu;

                    zhaiQuan2 = zhaiQuan2 - mairu2;
                    jiJin2 = yuE2 + mairu2;

                    dealBy += 1;
                    if (isLog) {

                        System.out.println(stockKlineBean.date);
                        System.out.println("收盘 " + stockKlineBean.shouPan + " midelK " + midelK);
                        System.out.println("rate " + rate);

                        System.out.println("买入 " + mairu);
                        System.out.println("基金 " + (rate * 100) + "% " + jiJin);
                        System.out.println("债券 " + (1 - rate) * 100 + "% " + zhaiQuan);
                        System.out.println("余额 " + (jiJin + zhaiQuan));
                        System.out.println();

                        System.out.println("买入2 " + mairu2);
                        System.out.println("基金2 " + (rate * 100) + "% " + jiJin2);
                        System.out.println("债券2 " + (1 - rate) * 100 + "% " + zhaiQuan2);
                        System.out.println("余额2 " + (jiJin2 + zhaiQuan2));
                        System.out.println();

                    }
                }
            }
            lastDealK = shouPan;
        }


        if (jiJin + zhaiQuan > maxMoney) {
            maxMoney = jiJin + zhaiQuan;
        }
        if (jiJin + zhaiQuan < minMoney) {
            minMoney = jiJin + zhaiQuan;
        }


        if (rate > maxRate) {
            maxRate = rate;
        }
        if (rate < minRate) {
            minRate = rate;
        }

        if (isLog) {
            if (rate == 1) {
                System.out.println("满仓 " + stockKlineBean.date);
            } else if (rate == 0) {
                System.out.println("清仓 " + stockKlineBean.date);
            }

            if (dealCount % 250 == 0) {
                System.out.println("第" + dealCount / 250 + "年");
                shouyi();
            }
        }

    }


    public void test1() {
        for (int i = 1; i <= loop; i++) {
            midelK += 100;
            double yinli = jiJin * 0.035;
            double yuE = jiJin + yinli;
            rate = rate - i * 0.01f;
            double maichu = 0;
            if (rate < 0) {
                rate = 0;
                maichu = jiJin;
            } else {
                maichu = yuE - (zhaiQuan + yuE) * rate;
            }

            zhaiQuan += maichu;
            jiJin = yuE - maichu;

            System.out.println("点位 " + midelK);
            System.out.println("盈利 " + yinli);
            System.out.println("卖出 " + maichu);
            System.out.println("基金 " + (rate * 100) + "% " + jiJin);
            System.out.println("债券 " + (1 - rate) * 100 + "% " + zhaiQuan);
            System.out.println("余额 " + (jiJin + zhaiQuan));
            System.out.println();
        }
        System.out.println("总余额 " + (jiJin + zhaiQuan));
    }

    public void test2() {
        for (int i = 1; i <= loop; i++) {
            midelK -= 100;
            double kuisun = jiJin * 0.035;
            double yuE = jiJin - kuisun;
            rate = rate + i * 0.01f;
            double mairu = 0;
            if (rate > 1) {
                rate = 1;
                mairu = zhaiQuan;
            } else {
                mairu = (zhaiQuan + yuE) * rate - yuE;
            }
            zhaiQuan = zhaiQuan - mairu;
            jiJin = yuE + mairu;

            System.out.println("点位 " + midelK);
            System.out.println("亏损 " + kuisun);
            System.out.println("买入 " + mairu);
            System.out.println("基金 " + (rate * 100) + "% " + jiJin);
            System.out.println("债券 " + (1 - rate) * 100 + "% " + zhaiQuan);
            System.out.println("余额 " + (jiJin + zhaiQuan));
            System.out.println();
        }
        System.out.println("总余额 " + (jiJin + zhaiQuan));
    }


    public void test3() {
        for (int i = 1; i <= loop; i++) {
            midelK += 100;
            double yinli = jiJin * 0.035;
            jiJin = jiJin + yinli;
            System.out.println("点位 " + midelK);
            System.out.println("盈利 " + yinli);
            System.out.println("基金 " + jiJin);
            System.out.println("债券 " + zhaiQuan);
            System.out.println("余额 " + (jiJin + zhaiQuan));
            System.out.println();
        }
        rate = 0.5f;
        jiJin = (jiJin + zhaiQuan) / 2;
        zhaiQuan = jiJin;
        System.out.println("总余额 " + (jiJin + zhaiQuan));
    }

    static List<Double> lianhua = new ArrayList<>();
    static List<Double> shouyilu = new ArrayList<>();

    public void shouyi() {

        if (isLog) {
            System.out.println("midelK " + midelK);

            System.out.println("买入次数 " + dealBy);
            System.out.println("卖出次数 " + dealSeal);

            System.out.println("最大比例 " + maxRate);
            System.out.println("最小比例 " + minRate);

            System.out.println("最高收益 " + maxMoney);
            System.out.println("最低收益 " + minMoney);

            System.out.println("当前收益 " + (jiJin + zhaiQuan));
            System.out.println("收益率 " + ((jiJin + zhaiQuan) - 20000) / 20000 * 100 + "%");

            double lianhua = APY((jiJin + zhaiQuan), (dealCount / 250));
            System.out.println((dealCount / 250) + " 年化 " + (lianhua * 100) + "%");
            System.out.println();

            System.out.println("当前收益2 " + (jiJin2 + zhaiQuan2));

        }


        if (currentFound != null) {
            System.out.println("index " + loopIndex);
            System.out.println(currentFound.get(0) + " : " + currentFound.get(1) + " " + currentFound.get(3));
        }
        double lianhua2 = APY((jiJin2 + zhaiQuan2), (dealCount / 250));
        lianhua.add(lianhua2);
        double shouyi = ((jiJin2 + zhaiQuan2) - 20000) / 20000 * 100;
        shouyilu.add(shouyi);

        System.out.println("收益率2 " + shouyi + "%");
        System.out.println((dealCount / 250) + " 年化2 " + (lianhua2 * 100) + "%");
        System.out.println();

    }


    public StockBean dayStockBean;
    public List<JijinBean> jijinBeanList;

    public StockKlineBean lastStockKlineBean;

    void test() {
        if (dayStockBean != null && jijinBeanList != null) {
            lastStockKlineBean = dayStockBean.klineList.get(dayStockBean.klineList.size() - 1);
            for (int i = 0; i < dayStockBean.klineList.size(); i++) {
                if ("2010-01-04".equals(dayStockBean.klineList.get(i).date)) {
                    dayStockBean.klineList = dayStockBean.klineList.subList(i, dayStockBean.klineList.size());
                    break;
                }
            }

            Collections.reverse(jijinBeanList);
            for (int i = 0; i < jijinBeanList.size(); i++) {
                if ("2010-01-04".equals(jijinBeanList.get(i).getFSRQ())) {
                    jijinBeanList = jijinBeanList.subList(i, jijinBeanList.size());
                    break;
                }
            }

            for (int i = 0; i < dayStockBean.klineList.size(); i++) {
                StockKlineBean stockKlineBean = dayStockBean.klineList.get(i);
                lastDealK += 1.34f;
                midelK += 1.34f;
                for (int j = 0; j < jijinBeanList.size(); j++) {
                    JijinBean jijinBean1 = jijinBeanList.get(j);
                    if (stockKlineBean.date.equals(jijinBean1.getFSRQ()) && jijinBean1.getJZZZL() != null && !jijinBean1.getJZZZL().equals("")) {
                        testFound(stockKlineBean, jijinBean1);
                        break;
                    }
                }
            }
            shouyi();
            rate();
        }
    }

    public void getKlines(String url) {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(10, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .build();
        Request.Builder builder = new Request.Builder()
                .url(url);
        builder.addHeader("Referer", "http://fundf10.eastmoney.com/");
        Request request = builder.get().build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new okhttp3.Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, @NotNull okhttp3.Response response) throws IOException {
                if (response.body() != null) {
                    String html = response.body().string();
                    String tag1 = "\"data\":";
                    int index1 = html.indexOf(tag1);
                    int index2 = html.lastIndexOf("}");
                    html = html.substring(index1 + tag1.length(), index2);
                    StockBean2 stockBean = GsonUtil.parse(html, StockBean2.class);
                    if (stockBean == null) {
                        System.out.println("sss" + url);
                    }
                    List<StockKlineBean> klineList = new ArrayList<>();
                    for (int i = 0; i < stockBean.klines.size(); i++) {
                        String line = stockBean.klines.get(i);
                        String[] item = line.split(",");
                        StockKlineBean stockKlineBean = new StockKlineBean();
                        stockKlineBean.date = item[0];
                        stockKlineBean.jinKai = Float.parseFloat(item[1]);
                        stockKlineBean.shouPan = Float.parseFloat(item[2]);
                        stockKlineBean.zuigao = Float.parseFloat(item[3]);
                        stockKlineBean.zuidi = Float.parseFloat(item[4]);
                        stockKlineBean.chengjiaoliang = Double.parseDouble(item[5]);
                        stockKlineBean.chengjiaoe = Double.parseDouble(item[6]);
                        stockKlineBean.zhenfu = Float.parseFloat(item[7]);
                        stockKlineBean.chg = Float.parseFloat(item[8]);
                        stockKlineBean.zde = Float.parseFloat(item[9]);
                        stockKlineBean.huanshou = Float.parseFloat(item[10]);
                        stockKlineBean.index = i;
                        klineList.add(stockKlineBean);
                    }
                    stockBean.klineList = klineList;
                    dayStockBean = stockBean;
                    test();
                }
            }
        });
    }


    public void getKlines2(String url) {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(10, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .build();
        Request.Builder builder = new Request.Builder()
                .url(url);

        builder.addHeader("Referer", "http://fundf10.eastmoney.com/");
        builder.addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Mobile Safari/537.36");
        builder.addHeader("gzip", "deflate");
        builder.addHeader("Cookie", "qgqp_b_id=620478141806799168524986f53c8a64; em_hq_fls=js; Eastmoney_Fund=050002; em-quote-version=topspeed; HAList=ty-1-000011-%u57FA%u91D1%u6307%u6570%2Cty-1-000001-%u4E0A%u8BC1%u6307%u6570%2Ca-sz-002761-%u6D59%u6C5F%u5EFA%u6295%2Ca-sz-300142-%u6C83%u68EE%u751F%u7269%2Cty-100-NDX100-%u7EB3%u65AF%u8FBE%u514B100%2Cty-100-NDX-%u7EB3%u65AF%u8FBE%u514B%2Cty-0-163406-%u5174%u5168%u5408%u6DA6LOF%2Cty-1-000012-%u56FD%u503A%u6307%u6570%2Cty-0-159887-%u94F6%u884CETF%2Ca-sz-300059-%u4E1C%u65B9%u8D22%u5BCC; ad_tc_221000003614433909=true; EMFUND0=05-17%2022%3A16%3A09@%23%24%u6613%u65B9%u8FBE%u884C%u4E1A%u9886%u5148%u6DF7%u5408@%23%24110015; EMFUND2=05-17%2022%3A17%3A34@%23%24%u5174%u5168%u5408%u6DA6%u6DF7%u5408%28LOF%29@%23%24163406; EMFUND4=05-17%2022%3A18%3A07@%23%24%u4E2D%u6B27%u65B0%u84DD%u7B79%u6DF7%u5408A@%23%24166002; EMFUND5=05-17%2022%3A18%3A26@%23%24%u8BFA%u5B89%u5148%u950B%u6DF7%u5408A@%23%24320003; EMFUND6=05-17%2022%3A19%3A59@%23%24%u4E2D%u6B27%u4EF7%u503C%u53D1%u73B0%u6DF7%u5408A@%23%24166005; EMFUND7=06-04%2000%3A24%3A17@%23%24%u534E%u590F%u5927%u76D8%u7CBE%u9009%u6DF7%u5408A@%23%24000011; EMFUND8=06-05%2021%3A27%3A09@%23%24%u4E1C%u5434%u5174%u4EAB%u6210%u957F%u6DF7%u5408A@%23%24010330; EMFUND1=06-05%2022%3A32%3A50@%23%24%u4EA4%u94F6%u65B0%u6210%u957F%u6DF7%u5408@%23%24519736; st_si=33551357803967; st_asi=delete; EMFUND9=06-06%2020%3A35%3A24@%23%24%u6613%u65B9%u8FBE%u4FE1%u7528%u503A%u503A%u5238C@%23%24000033; EMFUND3=06-06 20:52:43@#$%u5BCC%u56FD%u5929%u60E0%u6210%u957F%u6DF7%u5408A/B%28LOF%29@%23%24161005; st_pvi=17394662377812; st_sp=2021-08-29%2022%3A00%3A35; st_inirUrl=https%3A%2F%2Fwww.baidu.com%2Flink; st_sn=3; st_psi=20220606205247731-112200305283-0703102268");
        builder.addHeader("Host", "api.fund.eastmoney.com");
        builder.addHeader("Connection", "keep-alive");
        builder.addHeader("Accept-Language", "zh-CN,zh;q=0.9");

        Request request = builder.get().build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new okhttp3.Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, @NotNull okhttp3.Response response) throws IOException {
                if (response.body() != null) {
                    String html = response.body().string();
                    String tag1 = "\"LSJZList\":";


                    int index1 = html.indexOf(tag1);
                    int index2 = html.lastIndexOf("}]");
                    html = html.substring(index1 + tag1.length(), index2 + 2);


                    List<JijinBean> bean = GsonUtil.parse(html, new TypeToken<List<JijinBean>>() {
                    }.getType());

                    jijinBeanList = bean;
                    test();
                }
            }
        });
    }


}
